klotsagroupfandomcom-20200214-history
Ant Motion Tracking
=Explanation = :The following project is a demonstration of how to use DataTank for motion tracking. As you will see the tracking itself is not challenging rather the most difficult part is connecting the points, something that I will explain later on in the article. =Steps= :The first step is to drag in the source. This is really easy, just drag in the file and it should be there. You can access the file from my GitHub page. DataTank will handle this as a series of bitmap images that it can process. The next step is going to be converting it to grey map. The object to select is in the top menu Variable > 2D > 2D Mesh. Configure that object in the following way. Next we need to extract the background in order to do subtraction and it is convenient that the first frame does not have any ants. Again we select another 2D Mesh object like before. This time we pass it the 2D mesh object that just created. The object should be configured as follows. Now that we have the gray scale background as well as the grey scale image we can do a subtraction for all of the frame of the video. This is done by again creating a new 2D mesh object. It should be configured as shown. In order to extract out the contour first we need a threshold, in order to make that easy to manipulate we will create a real number object. This can be created selecting the pi symbol and then selecting slider. The slider object should then be configured to look like the following. The range slider can be dragged around as seen fit to get the outlines correctly later on. The next step is to create a 2D contour object. This is found in the same place as the 2D mesh objects. It should be configured to look like the following. It, when properly thresholded should pick out the correct outline of the ants. The next step is to clean up that data, removing the heads of the ants as well as other small loops. This is done by creating another mesh object and configuring it as shown. The tolerance, which is manually set, gets rid of the excess loops. If you want to visualize the process you can draw it by clicking on the gear next to “Ant outline approximation”, selecting drawing and then 1D plot or others if you wish. From the “ant outline approximation” object we can find the center of mass of each of the loops or ants. This is done with the creation of a 2D point value collection object. This object is selected from the same place as the outline object. It is configured as shown below. Next, since this point values and we just want points we need to extract them into another object this one called 2D point collection. Next we need to compress it into an object that contains all of the points for every time frame, this is called a series type object. In order to get this first you go to the menu bar, select series just below group. Then configure as shown below, once you select the the correct variable the type picture in the top left corner of the object should change. Now we want to have the paths which the ants traveled, later on this can be used to represent their travel with frame by frame velocity vectors. To create this will be a bit more involved and will require the creation of an external program. If the steps for doing this are unclear they are covered in more detail in the Flocking example '''Link to it here. '''Another contour object will be created and configured as follows. The code that you will paste in to replace the old will be: class SingleList { public: SingleList() {howManyPoints = 0; points = DTMutableDoubleArray(2,10);} // Initialize DTMutableDoubleArray points; // 2xN array of xy values int howManyPoints; DTPoint2D lastPoint; int timeIndex; void AddPoint(const DTPoint2D &addThis,int timeI) { if (howManyPoints points.n()) { // at the end of the array points = IncreaseSize(points,points.Length()); } points(0,howManyPoints) = addThis.x; points(1,howManyPoints) = addThis.y; howManyPoints++; lastPoint = addThis; timeIndex = timeI; } DTPath2D ConvertToPath(){ // The first column needs to be the length DTMutableDoubleArray loop(2,howManyPoints+1); // [ 0 x1 .... xN] // [ N y1 .... yN] loop(0,0) = 0; loop(1,0) = howManyPoints; for (int i=0;i